package com.axend.aerosense.common.adapter;

import androidx.databinding.DataBindingUtil;

import com.axend.aerosense.common.R;
import com.axend.aerosense.common.base.IEventBaseContent;
import com.axend.aerosense.common.bean.AlarmBean;
import com.axend.aerosense.common.databinding.CommonEventItemBinding;
import com.axend.aerosense.common.util.DateUtil;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

public class CommonProvider extends BaseItemProvider<IEventBaseContent> {
    private CommonEventItemBinding viewDataBinding;// 绑定View
    /**
     * 当 ViewHolder 创建完毕以后，会执行此回掉
     * 可以在这里做任何你想做的事情
     */
    @Override
    public void onViewHolderCreated(@NotNull BaseViewHolder viewHolder, int viewType) {
        super.onViewHolderCreated(viewHolder, viewType);
        // 绑定View
        viewDataBinding = DataBindingUtil.bind(viewHolder.itemView);
    }

    @Override
    public int getItemViewType() {
        return 1;
    }

    @Override
    public int getLayoutId() {
        return R.layout.common_event_item;
    }

    @Override
    public void convert(@NotNull BaseViewHolder baseViewHolder, IEventBaseContent baseContent) {
        if (baseContent == null) {
            return;
        }

        viewDataBinding = baseViewHolder.getBinding();
        viewDataBinding.commonEventName.setText(baseContent.getEventTypeName());
        viewDataBinding.commonRoomName.setText(baseContent.getEventRoomName());
        viewDataBinding.commonEventTime.setText(DateUtil.getStringDateJudgeToday(baseContent.getEventTime()));
        if(baseContent instanceof AlarmBean){
            viewDataBinding.commonWarningHistroyCircular.setBackgroundResource(R.drawable.common_red);
        }else{
            viewDataBinding.commonWarningHistroyCircular.setBackgroundResource(R.drawable.common_yellow);
        }
    }
}
